﻿using UnityEngine;
using System.Collections;
using Dict.DataModel;
using ProtoBuf.Message;

namespace Room
{
    public class RCUIFishGuide : RCUIFish
    {
        
        public RCUIFishGuide(RoomCharactor owner)
            : base(owner)
        {
            type = UIType.FishGuide;
        }

        public override void Init(TableFieldResource fish, TableFieldResourcePos fishPos)
        {
            base.Init(fish, fishPos);
            InitButton(() =>
            {
                StaticData.resId = fish.id;
                StaticData.resPosId = fishPos.posId;
                {
                    var self = owner.charactorManager.GetSelfCharactor();
                    var ai = self.ai as RCAIActor;
                    ai.SwitchState(PlayerAIState.Fishing);
                }

                UI.UIFieldRunMap.OpenGetResourceWaiting(() =>
                {
                    CSGuideFish msg = new CSGuideFish();
                    NetAPI.SendHttp(OpDefine.CSGuideFish, msg, (packet, bSuccess) =>
                      {
                          if (bSuccess)
                          {
                              var recv = packet.kBody as SCGuideFish;
                              UI.UIFieldRunMap.DisplayGetResource(recv.get);
                              //UI.UIFieldRunMap.DisplayGetResource(new ResultObject());
                              owner.charactorManager.DestroyCharactor(owner.name);

                              var self = owner.charactorManager.GetSelfCharactor();
                              var ai = self.ai as RCAIActor;
                              ai.SwitchState(PlayerAIState.Normal);
                          }
                      });
                });
            });
            SetButtonSprite("UI_yewai_biaoshi_diaoyu");
            SetButtonDepth(5);


        }

        public override void Click()
        {
            OnClick();
        }

        protected override void OnClick()
        {

        }
        public override void DoStart()
        {
            base.DoStart();
            
        }

    }
}
